<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script>
        function sendAjax(){
            $.ajax({
                type:'delete',
                url:'http://127.0.0.1:8080/springmvc/ajax2',
                dataType:'json',
                success:function(result){
                    console.log(result)
                }
            })
        }

        function sendAjax2(){
            // var data = {
            //     id:1001,
            //     username:"zhangsan",
            //     password:"123",
            //     age:18,
            //     birthday:"2021-09-09"
            // }
            // var data = [12,45,76,9]

            // var data = {
            //     uid:1001
            // }

            // $.ajax({
            //     type:'post',
            //     url:'param6',
            //     contentType:'application/json;charset=utf-8', // 数据格式为json字符串
            //     data:JSON.stringify(data), // 传入的参数为json字符串
            //     dataType:'json',
            //     success:function(res){
            //         console.log(res)
            //     }
            // })

            var data = {
                id:1001,
                username:"张三",
                password:"123",
                age:18,
                birthday:"2021-09-09"
            }

            $.ajax({
                type:'delete',
                url: 'path/test1',
                // contentType:'application/x-www-form-urlencoded;charset=utf-8', // 默认数据为表单数据
                // data:data,
                dataType: 'json',
                success:function(res){
                    console.log(res)
                }
            })
        }

        function doUpload(){
            // 文件上传时必须将数据封装为FormData对象
            // var data = new FormData()
            // data.append('name',$('#name').val())
            // data.append('avatar',$('#avatar')[0].files[0])
            var data = new FormData($('#uploadForm')[0])

            $.ajax({
                type:'post', // 请求方式必须为post
                url:'upload',
                data:data,
                contentType:false, // 文件上传必须为false，相当于设置为multipart/form-data
                processData:false, // 文件上传必须为false，不需要对数据进行处理
                success:function(res){
                    console.log(res)
                }*
            })

        }
    </script>
</head>
<body>
    welcome!!!!
    <img src="imgs/turtle.png" alt="" style="width: 200px;">
    <hr>

    <!--发送请求-->
    <button onclick="sendAjax()">发送Ajax请求</button>
    <hr>

    <button onclick="sendAjax2()">发送请求</button>
    <hr>

    <form id="uploadForm" enctype="multipart/form-data">
        姓名：<input type="text" name="name" id="name"> <br>
        头像：<input type="file" name="avatar" id="avatar"> <br>
        <input type="button" value="提交" onclick="doUpload()">
    </form>
</body>
</html>